home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 37 / Amiga Format CD37 (1999-02-16)(Future Publishing)(GB)(Track 1 of 3)[!][issue 1999-03].iso / -screenplay- / shareware / invasionforce / source / includes / cyber_protos.h < prev    next >
C/C++ Source or Header  |  1999-01-09  |  17KB  |  492 lines

  1. /*
  2. AI Code for Invasion Force - an Explore/Conquer Strategic Wargame
  3. Copyright (C) 1996  Brannen Hough
  4.  
  5. This program is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU General Public License
  7. as published by the Free Software Foundation; either version 2
  8. of the License, or any later version.
  9.  
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. GNU General Public License for more details.
  14.  
  15. You should have received a copy of the GNU General Public License
  16. along with this program; if not, write to the Free Software
  17. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18. */
  19.  
  20. /* Prototypes for functions defined in
  21. cyber_xxxx.c files
  22.  */
  23.  
  24. /***************************
  25. ****    Externs        ****
  26. ***************************/
  27. extern  int     AIDataFlag;
  28. #define AI_DATA_FLAG_LIMIT 5
  29.  
  30. extern  struct  GovHist  H;
  31.  
  32. extern  struct  rtHandlerInfo *AIhandle;
  33.  
  34. extern  int     NewGov;
  35. extern  int     NewUnit;
  36.  
  37. extern  struct  GovReqs         LastReq;
  38.  
  39. extern struct MinList  GovList;
  40.  
  41. extern char outbuf[];
  42.  
  43. extern int *MoveMap;
  44.  
  45. extern enum Direction DirArray[8][6];
  46.  
  47. extern char DirString[6][10];
  48.  
  49. extern char ModeString[9][15];
  50.  
  51. extern char UnitString[13][15];
  52.  
  53. extern struct MinList  OpenList;
  54. extern struct MinList  DoneList;
  55. extern int    *PathMap;
  56. extern int     PathMapX;
  57. extern int     PathMapY;
  58.  
  59. // This must be longer than the furthest an aircraft can reach
  60. #define        MAX_PATH     25
  61. extern int     Path[MAX_PATH];
  62.  
  63. //extern int     PathDiv;
  64. extern int     PathLength;
  65. extern int PathCost;
  66.  
  67.  
  68. /***********************************
  69. ****    Defines            ****
  70. ***********************************/
  71.  
  72. /* Do we show AI messages?  Uncomment this if desired */
  73. //#define SHOW_AI_MSG 1
  74.  
  75. /* How many characters we'll need for governor names */
  76. #define GOV_NAME_LEN        8
  77.  
  78. /* The number of requests that will be collected. Ones
  79.     in excess of this number will be culled down 
  80.     by priority.  Only one request will be selected
  81.     when all are in.
  82.     */
  83. #define MAX_GOV_REQS            20
  84.  
  85. /* Superceded, no longer used */
  86. #define GOVERNOR_AREA           10
  87.  
  88. /* How far out (in x and y) we will scout in EXPLORE mode
  89.     As and experiment, I'm changing this to 4.  At 4,
  90.     we will have a 15 move search triangle instead of
  91.     17, so will go from 4 turns per leg to 3 per leg.
  92.     See if this holds up.  Lose coverage of 46 hexes
  93.     on the four legs - from 151 to 105 (?).
  94.     */
  95. #define GOVERNOR_RADIUS          4  /* Was 5 */
  96.  
  97. /* The bounds of the larger area of interest for a Governor.
  98.     Outside this area, Governors don't keep track of
  99.     what is going on.
  100.     */
  101. #define EXTENDED_RADIUS        10
  102.  
  103. /* This next is how far the fighter can reach on a full tank */
  104. #define FIGHTER_REACH        20
  105.  
  106. /* This is how long a list of unit type preferences we can 
  107.     make.  Should stay more than we need, especially
  108.     since there are only 13 types in the game right now.
  109.     */
  110. #define MAX_PREFS               10
  111.  
  112. /* This next is the bonus percentage for selection given to
  113.     a unit type that is already in production
  114.     */
  115. #define CURRENT_PRODUCT_BONUS   20
  116.  
  117. /* Used to break out of loops, large compare value for initial
  118.     "get the smallest" searches, etc.
  119.     */
  120. #define BIG_NUMBER           30000
  121.  
  122. /* Mirror the ones in game_play.c */
  123. #define UNIT_DONE       3
  124. #define UNIT_LOST       4
  125. #define INVISIBLE       0
  126. #define VISIBLE         1
  127.  
  128. /* One for the gov_find_distance function */
  129. #define ENEMY           1
  130. #define FRIENDLY        0
  131.  
  132. /* No tokens for these orders.  For computer player only.  
  133.     Hope noone objects!
  134.     */
  135. #define C_ORDER_RANDOM    101    /* For just wandering around for a while */
  136. #define C_ORDER_PATH_TO    102    /* For when a GOTO fails and we need to
  137.                     seek out an indirect path to goal */
  138. #define C_ORDER_PATROL    103    /* Human players may want this too */
  139. #define C_ORDER_CIRCLE  104
  140. #define C_ORDER_GOTO    105
  141. #define C_ORDER_HEADTO  106     /* We need this as a stopgap */
  142. #define C_ORDER_SENTRY  107
  143. #define C_ORDER_LOAD    108
  144. #define C_ORDER_UNLOAD  109
  145. #define C_ORDER_FORTIFY 110
  146. #define C_ORDER_3_PT_GO 111     /* Point A to Point B to home */
  147. #define C_ORDER_OUT_RET 112     /* Point A to home */
  148. #define C_ORDER_HOME    113     /* Go home */
  149. #define C_ORDER_STORAGE 114
  150. #define C_ORDER_HUNT    115
  151. #define C_ORDER_RECON   116
  152. #define C_ORDER_WALK_COASTLINE 117
  153.  
  154.  
  155. #define AI5_PATH_EXISTS  ((Path[0] != -1))
  156. #define AI5_PATH_BEST  1
  157. #define AI5_PATH_GOOD  4
  158. #define AI5_PATH_FAST  7
  159. #define AI5_PATH_FASTEST 10
  160. #define MAX_PATH 25
  161.  
  162.  
  163. /* This one is for debugging the computer player */
  164. #ifdef SHOW_AI_MSG
  165. #define  DEBUG_AI(string)  if (!rtEZRequestTags(string,"Continue|Abort", \
  166.      NULL,NULL, RTEZ_Flags,EZREQF_CENTERTEXT,RT_Window,map_window, \
  167.      RT_ReqPos,REQPOS_CENTERWIN,RT_LockWindow,TRUE,TAG_END )) \
  168.      { if (AIhandle != NULL)  unpost_it(AIhandle); AIhandle = NULL; \
  169.      clean_exit(0, NULL); }
  170. #endif
  171. #ifndef SHOW_AI_MSG
  172. #define  DEBUG_AI(string)
  173. #endif
  174.  
  175. /**********************************
  176. ****    Definitions        ***
  177. **********************************/
  178.  
  179. /* Let's make these values different, so I have a chance to tell if
  180.   something is wrong
  181.   */
  182. #define GOV_TYPE_BASE 201
  183. enum    GovType {
  184.     GOV_CITY = GOV_TYPE_BASE,
  185.     GOV_PORT,
  186.     GOV_ISLAND,
  187.     GOV_TRANSPORT,
  188.     GOV_CARRIER,
  189.     GOV_BATTLESHIP
  190. };
  191.  
  192. /* Let's make these values different, so I have a chance to tell if
  193.   something is wrong
  194.   */
  195. #define GOV_MODE_BASE 301
  196. enum    GovMode {
  197.     GOV_NOCITY = GOV_MODE_BASE,
  198.     GOV_SEARCH,
  199.     GOV_SUPPORT,        
  200.     GOV_ATTACK,         
  201.     GOV_DEFEND,         
  202.     GOV_OUTNUMBERED,
  203.     GOV_TAKEN
  204. };
  205.  
  206. /* This is used for Governors requests - this records the unit types
  207.   that it wants to build and the priority it places on each one.
  208.   A random number from 1 to 100 is rolled and the prefs are gone 
  209.   through in order until a type is selected - each one is associated
  210.   with a number and all the types listed will equal 100 or more.
  211.   For example, if we want a 70% chance to request a RIFLE and a
  212.   30% chance for a FIGHTER, we would set the structure to 
  213.       type[0] = RIFLE, type[1] = FIGHTER, priority[0] = 70,
  214.       priority[1] = 30
  215.       */
  216. struct  GovPrefs {
  217.     short   type[MAX_PREFS];
  218.     short   priority[MAX_PREFS];
  219. };
  220.  
  221.  
  222. struct    GovReqs {
  223.     int    type;
  224.     int    req_gov;
  225.     int    priority;
  226. };
  227.  
  228. /* Used to make decisions about what to do.  (48 ints per governor is a lot
  229.     since we have one governor for each city. We'll see how the memory 
  230.   usage works out.  Shorts should work fine.)  Only 13 values are used 
  231.   currently for units - with 11 being a militia (brought into existance 
  232.   to defend a city from direct attack only) and 12 for cities.
  233.   But I'll leave both at 16 for growth. */
  234. struct  GovHist {
  235.     unsigned short int  TotalCities;
  236.     unsigned short int  TotalMyCities;
  237.     unsigned short int    TotalMyUnits;
  238.     unsigned short int    TotalEUnits;
  239.     unsigned short int    TerrainCounts[16];
  240.     unsigned short int    UnitCounts[16];
  241.     unsigned short int    EnemyCounts[16];
  242. };
  243.  
  244.  
  245. /* This structure contains the data needed for the Governors, which
  246.     will control and fight the computer's units.  The relevant
  247.     data is the type - City or Carrier, what mode it is in -
  248.     attacking, defending, exploring, supporting, etc.  For cities,
  249.     the requests on hand from the top 20 (or whatever) governors. */
  250. struct  GovNode {
  251.     struct  MinNode gnode;  // must stay the first item
  252.     enum    GovType    type; // must stay the second item - fix SaveAIPlayers
  253.                             // if either one is changed.
  254.     enum    GovMode    mode;
  255.     unsigned  char    flags;  /* Eight flags to be defined after
  256.                  this declaration. */
  257.     short   owner;    /* Added to take governors to list entities */
  258.     short   x;          /* The X and Y of the city's or unit's location */
  259.     short   y;
  260.     short   targx;
  261.     short   targy;      /* Target of the governor's attention when 
  262.                            applicable */
  263.     short   searchx;
  264.     short   searchy;    /* Where the Governor is searching to now */
  265.     
  266.     short   startx;
  267.     short   starty;
  268.     short   endx;
  269.     short   endy;    /* Contain the coordinates of the area of
  270.                 interest of the governor */
  271.  
  272.     short   Estartx;
  273.     short   Estarty;
  274.     short   Eendx;
  275.     short   Eendy;    /* Extended are of interest for the governor */
  276.  
  277.     int     ID;         /* name of the governor - used to tell the
  278.                           units apart.  Use more than we'll need. */
  279.  
  280.     struct  GovHist hist;   /* Histogram of terrain for this governor -
  281.       how much is unknown, land, water, etc. - also how many
  282.           enemy sightings there are and friendly units.  Good for 
  283.       recovering from a restore as the data does not have
  284.       to be saved, just regenerated. */
  285.                             
  286.     struct  GovReqs req;    /* The current request that is being built
  287.                       Of course, only meaningful for city governors. */
  288. };
  289.  
  290. #define  IsModeChange(gov)      (gov->flags & 0x01)
  291. #define  SetModeChange(gov)     (gov->flags = gov->flags | 0x01)
  292. #define  ClearModeChange(gov)    (gov->flags = gov->flags & 0xFE)
  293.  
  294. #define  IsNeutralCity(gov)     (gov->flags & 0x02)
  295. #define  SetNeutralCity(gov)    (gov->flags = gov->flags | 0x02)
  296. #define  ClearNeutralCity(gov)  (gov->flags = gov->flags & 0xFD)
  297.  
  298. #define  IsCityTaken(gov)    (gov->flags & 0x04)
  299. #define  SetCityTaken(gov)    (gov->flags = gov->flags | 0x04)
  300. #define  ClearCityTaken(gov)    (gov->flags = gov->flags & 0xFB)
  301.  
  302. #define  IsSearchDone(gov)    (gov->flags & 0x08)
  303. #define  SetSearchDone(gov)    (gov->flags = gov->flags | 0x08)
  304. #define  ClearSearchDone(gov)   (gov->flags = gov->flags & 0xF7)
  305.  
  306. #define  IsCityThreatened(gov)    (gov->flags & 0x10)
  307. #define  SetCityThreatened(gov)    (gov->flags = gov->flags | 0x10)
  308. #define  ClearCityThreatened(gov)   (gov->flags = gov->flags & 0xF7)
  309.  
  310.  
  311. struct HexReport {
  312.     int  TotalEUnits;
  313.     int  TotalMyUnits;
  314.     int  AtRisk;
  315.     int  CanAttack;
  316.     int  Gain;
  317.     int  Risk;
  318.     int  Odds;
  319. };
  320.  
  321.  
  322. struct PathNode {
  323.     struct MinNode  pnode;
  324.     short  x;
  325.     short  y;
  326.     long   cost;
  327.     long   eta;
  328. };
  329.  
  330.  
  331. /***************************
  332. ****    Prototypes    ****
  333. ***************************/
  334. /* Interface and Cleanup */
  335. void    set_automated_production (struct City *);
  336. void    cleanup_computer (void);
  337. int     do_computer_city_production(void);
  338. void    make_new_unit(struct City*);
  339. void    computer_player_moves (void);
  340. int     SaveAIPlayers( BPTR, char* );
  341. int     LoadAIPlayers( BPTR, char* );
  342.  
  343. /**************************
  344. ****  Cyber #1 Protos  ****
  345. **************************/
  346. struct GovNode*  AI1_locate_gov( struct City* );
  347. struct GovNode*  AI1_add_gov( struct City* );
  348. void  AI1_set_gov_prod (struct City*, struct GovNode*);
  349. void  AI1_play_turn ( int );
  350. void  AI1_setup_area_of_interest( struct GovNode* );
  351. void  AI1_do_all_histograms(void);
  352. void  AI1_do_one_histogram( struct GovNode* );
  353. void  AI1_give_orders(void);
  354. int   AI1_do_unit_actions(void);
  355. struct GovNode*  AI1_FindOwner( struct Unit* );
  356. void  AI1_computer_give_orders(struct Unit*, int, short, short,short,short,int);
  357. void  AI1_execute_standing_order( struct Unit* );
  358. int   AI1_look_around( struct Unit* );
  359. int   AI1_calc_dir (enum Direction , short, short, short*, short*);
  360. int   AI1_command_headto( struct Unit* );
  361. void  AI1_command_random( struct Unit* );
  362. void  AI1_set_gov_mode( struct GovNode* );
  363. void  AI1_clear_all_orders( struct GovNode* );
  364. int   New_AI1_do_unit_actions(void);
  365. int   New_AI1_look_around( struct Unit* );
  366. void  New_AI1_play_turn ( int );
  367. void  New_AI1_give_orders(void);
  368. void  New_AI1_execute_standing_order( struct Unit* );
  369.  
  370.  
  371. /**************************
  372. ****  Cyber #2 Protos  ****
  373. **************************/
  374. void  AI2_set_gov_prod (struct City*, struct GovNode*);
  375. void  AI2_get_gov_req (struct GovNode*, struct City* );
  376. int   AI2_calc_distance (short, short, short, short );
  377. void  AI2_play_turn (int);
  378. struct GovNode*  AI2_locate_gov( struct City* );
  379. void  AI2_setup_area_of_interest( struct GovNode* );
  380. void  AI2_do_all_histograms( void );
  381. void  AI2_set_gov_mode( struct GovNode* );
  382. void  AI2_give_orders(void);
  383. int   AI2_do_unit_actions(void);
  384. void  AI2_computer_give_orders(struct Unit*, int, short, short,
  385.       short, short, int);
  386. struct MapIcon* AI2_FindClosestEnemyUnit( short, short, int );
  387. int   AI2_look_around( struct Unit* );
  388. void  AI2_execute_standing_order( struct Unit* );
  389. int   AI2_command_hunt( struct Unit* );
  390.  
  391. /**************************
  392. ****  Cyber #3 Protos  ****
  393. **************************/
  394. void  AI3_set_gov_prod( struct City*, struct GovNode* );
  395. void  AI3_get_gov_req( struct GovNode*, struct City* );
  396. void  AI3_setup_area_of_interest( struct GovNode*, int, int );
  397. int   AI3_calc_path( short, short, short, short, short, int, int);
  398. int   AI3_calc_access( short, short, short, short, short);
  399. void  AI3_play_turn (int);
  400. struct GovNode*  AI3_locate_gov( struct City* );
  401. void  AI3_do_all_histograms( void );
  402. void  AI3_set_gov_mode( struct GovNode* );
  403. void  AI3_give_orders(void);
  404. void  AI3_taken_orders( struct Unit*, struct GovNode* );
  405. void  AI3_defend_orders( struct Unit*, struct GovNode* );
  406. void  AI3_search_orders( struct Unit*, struct GovNode* );
  407. void  AI3_default_orders( struct Unit*, struct GovNode* );
  408. int   AI3_do_unit_actions(void);
  409. void  AI3_computer_give_orders(struct Unit*, int, short, short,
  410.       short, short, int);
  411. void  AI3_select_recon_hex( struct Unit*, struct GovNode* );
  412. int   AI3_look_around( struct Unit* );
  413. void  AI3_execute_standing_order( struct Unit* );
  414. struct GovNode*  AI3_add_gov( struct City* );
  415. struct GovNode*  AI3_FindClosestCityGov( struct Unit*, int );
  416. struct MapIcon*  AI3_FindClosestEnemyCity( struct Unit*, int );
  417. int   AI3_command_recon( struct Unit* );
  418. void  AI3_command_random( struct Unit* );
  419. int   AI3_AssertUnit( struct Unit* );
  420. void  AI3_Ad_Lib( struct Unit* );
  421. void  AI3_orders_for_unit(struct Unit*);
  422. /************************
  423. ****  Cyber #4 Protos ***
  424. ************************/
  425. void  AI4_set_gov_prod( struct City*, struct GovNode* );
  426. void  AI4_get_gov_req( struct GovNode*, struct City* );
  427. struct GovNode*  AI4_locate_gov( struct City* );
  428. void  AI4_set_gov_mode( struct GovNode* );
  429. void  AI4_play_turn (int);
  430. int   AI4_do_unit_actions(void);
  431. int   AI4_look_around( struct Unit* );
  432. void  AI4_execute_standing_order( struct Unit* );
  433. int   AI4_command_goto( struct Unit* );
  434. void  AI4_give_orders(void);
  435. void  AI4_taken_orders( struct Unit*, struct GovNode* );
  436. void  AI4_defend_orders( struct Unit*, struct GovNode* );
  437. void  AI4_computer_give_orders(struct Unit*, int, short, short,
  438.       short, short, int);
  439. int   AI4_command_walk_coastline(struct Unit*);
  440. void  AI4_orders_for_unit(struct Unit*);
  441. /************************
  442. ****  Cyber #5 Protos ***
  443. ************************/
  444. void  AI5_CalcPath(short, short, short, short, short, int);
  445. long  AI5_GetCost( short, short);
  446. long  AI5_GetDist( short, short, short, short);
  447. void  AI5_OpenListInsertSorted( struct PathNode* );
  448. struct PathNode* AI5_OpenListGetBest(void);
  449. void  AI5_set_gov_prod( struct City*, struct GovNode* );
  450. void  AI5_get_gov_req( struct GovNode*, struct City*, enum GovType );
  451. void  AI5_set_gov_mode( struct GovNode* );
  452. struct Unit* AI5_LocateUnit( struct GovNode* );
  453. int   AI5_select_from_prefs( struct GovPrefs*, short );
  454. int   AI5_recommend_action( struct Unit*, int, int );
  455. void  AI5_evaluate_hex( struct Unit*, short, short, struct HexReport* );
  456. int   AI5_unit_value ( short );
  457. int   AI5_evaluate_odds ( struct Unit*, short, short, short, int );
  458. void  AI5_get_city_req( struct GovNode*, struct City*,enum GovType );
  459. void  AI5_get_island_req( struct GovNode*, struct City*, enum GovType );
  460. void  AI5_get_transport_req( struct GovNode*, struct City*, enum GovType );
  461. void  AI5_get_carrier_req( struct GovNode*, struct City*, enum GovType );
  462. void  AI5_get_battleship_req( struct GovNode*, struct City*, enum GovType );
  463. void  AI5_play_turn ( int);
  464. void  AI5_do_all_histograms( void );
  465. void  AI5_give_orders( void );
  466. void  AI5_default_orders( struct Unit* );
  467. void  AI5_city_orders( struct GovNode*, struct Unit* );
  468. void  AI5_port_orders( struct GovNode*, struct Unit* );
  469. void  AI5_island_orders( struct GovNode*, struct Unit* );
  470. void  AI5_transport_orders( struct GovNode*, struct Unit* );
  471. void  AI5_carrier_orders( struct GovNode*, struct Unit* );
  472. void  AI5_battleship_orders( struct GovNode*, struct Unit* );
  473. int   AI5_do_unit_actions( void );
  474. int   AI5_can_attack( short, short, short, short );
  475. void  AI5_command_goto( struct Unit* unit );
  476. double AI5_CalcWinOdds( double, int, int, int, int, double );
  477. double AI5_CalcOddsAdjust( int );
  478. //**************************
  479. //*** Cyber Orders Protos **
  480. //**************************
  481. int   DoUnitActions( int, int );
  482. void  ExecuteStandingOrder( struct Unit* );
  483. void  CommandGoto( struct Unit* );
  484. void  CommandRandom( struct Unit* );
  485. void  CommandHunt( struct Unit* );
  486. struct MapIcon*  FindClosestEnemyIcon( struct Unit*, int );
  487. void  CommandRecon( struct Unit* );
  488. void  CommandWalkCoastline( struct Unit* );
  489. void  ComputerGiveOrders(struct Unit*, int, short, short,
  490.       short, short, int);
  491. void  AIAddLib( struct Unit* );
  492.